use "HSSC replication data\Gallup data\cleaned_worldpoll_microdata.dta", clear

cd "`root_dir'\HSSC replication data\Findings\"

*Summary stats
tab yrm

drop if harm==.
tab month if year==2020
tab month if year==2021
sum harm_index  unemployed affected_alot  ///
 temp_layoff lost_hours lost_income lost_job  ///
 living_worse low_life Yworry  not_enough_food ///
 city suburb town foreign out_labor elementary secondary tertiary ageg1 ageg2 ageg3 ageg4 ageg5 ageg6 ageg7 male incQ1 incQ2 incQ3 incQ4   [aw=WGT], sep(0)

tab mode_ind
bysort period: tab mode_ind
bysort month: tab mode_ind if year==2020
tab time_string

**************
**ALT MODELS for SUPPLEMENT**
******* 

*Standardize
foreach x in living_worse low_life Yworry not_enough_food harm_index harm_factor covid_econ  layoff temp_layoff  lost_job  affected_alot harm_pca {
egen ZZ`x'=std(`x')
replace `x'=ZZ`x'
}

foreach y in living_worse low_life Yworry not_enough_food {
areg  `y' harm_index ///
 city suburb town foreign out_labor elementary secondary ageg1 ageg2 ageg3 ageg4 ageg5 ageg6  male incQ1 incQ2 incQ3 incQ4  ///
 married have_children cath protest_christ christ muslim hindu buddhist jew  atheist confus ///
 yrm1 yrm2 yrm3 yrm4 yrm5 yrm6 yrm7  yrm9 [aw=WGT], ab(WP5) cl(WP5)
outreg2 using "Sup_Regress_Welfare_on_Alt_Measures.xls",  excel adjr2 dec(3) label ///
addnote("All models include country fixed effects. Errors are clustered at country level.")  
}


foreach y in living_worse low_life Yworry not_enough_food {
areg  `y' harm_factor harm_index ///
 city suburb town foreign out_labor elementary secondary ageg1 ageg2 ageg3 ageg4 ageg5 ageg6  male incQ1 incQ2 incQ3 incQ4  ///
 married have_children cath protest_christ christ muslim hindu buddhist jew  atheist confus ///
 yrm1 yrm2 yrm3 yrm4 yrm5 yrm6 yrm7  yrm9 [aw=WGT], ab(WP5) cl(WP5)
outreg2 using "Sup_Regress_Welfare_on_Alt_Measures.xls",  excel adjr2 dec(3) label ///
addnote("All models include country fixed effects. Errors are clustered at country level.")  
}

foreach y in living_worse low_life Yworry not_enough_food {
areg  `y' harm_pca harm_index ///
 city suburb town foreign out_labor elementary secondary ageg1 ageg2 ageg3 ageg4 ageg5 ageg6  male incQ1 incQ2 incQ3 incQ4  ///
 married have_children cath protest_christ christ muslim hindu buddhist jew  atheist confus ///
 yrm1 yrm2 yrm3 yrm4 yrm5 yrm6 yrm7  yrm9 [aw=WGT], ab(WP5) cl(WP5)
outreg2 using "Sup_Regress_Welfare_on_Alt_Measures.xls",  excel adjr2 dec(3) label ///
addnote("All models include country fixed effects. Errors are clustered at country level.")  
}

foreach y in living_worse low_life Yworry not_enough_food {
areg  `y' layoff temp_layoff  lost_job ///
 city suburb town foreign out_labor elementary secondary ageg1 ageg2 ageg3 ageg4 ageg5 ageg6  male incQ1 incQ2 incQ3 incQ4  ///
 married have_children cath protest_christ christ muslim hindu buddhist jew  atheist confus ///
 yrm1 yrm2 yrm3 yrm4 yrm5 yrm6 yrm7  yrm9 [aw=WGT], ab(WP5) cl(WP5)
outreg2 using "Sup_Regress_Welfare_on_Alt_Measures.xls",  excel adjr2 dec(3) label ///
addnote("All models include country fixed effects. Errors are clustered at country level.")  
}

foreach y in living_worse low_life Yworry not_enough_food {
areg  `y' covid_econ harm_index ///
 city suburb town foreign out_labor elementary secondary ageg1 ageg2 ageg3 ageg4 ageg5 ageg6  male incQ1 incQ2 incQ3 incQ4  ///
 married have_children cath protest_christ christ muslim hindu buddhist jew  atheist confus ///
 yrm1 yrm2 yrm3 yrm4 yrm5 yrm6 yrm7  yrm9 [aw=WGT], ab(WP5) cl(WP5)
outreg2 using "Sup_Regress_Welfare_on_Alt_Measures.xls",  excel adjr2 dec(3) label ///
addnote("All models include country fixed effects. Errors are clustered at country level.")  
}

foreach y in living_worse low_life Yworry not_enough_food {
areg  `y' covid_econ affected_alot ///
 city suburb town foreign out_labor elementary secondary ageg1 ageg2 ageg3 ageg4 ageg5 ageg6  male incQ1 incQ2 incQ3 incQ4  ///
 married have_children cath protest_christ christ muslim hindu buddhist jew  atheist confus ///
 yrm1 yrm2 yrm3 yrm4 yrm5 yrm6 yrm7  yrm9 [aw=WGT], ab(WP5) cl(WP5)
outreg2 using "Sup_Regress_Welfare_on_Alt_Measures.xls",  excel adjr2 dec(3) label ///
addnote("All models include country fixed effects. Errors are clustered at country level.")  
}

 
***FIGURES 1--main text, microeconomic evidence on wellbeing and emotion

*TABLE--output
foreach x in harm_index  unemployed affected_alot  ///
 temp_layoff lost_hours lost_income lost_job  { 
areg living_worse `x' ///
 city suburb town foreign out_labor elementary secondary ageg1 ageg2 ageg3 ageg4 ageg5 ageg6  male incQ1 incQ2 incQ3 incQ4  ///
 married have_children cath protest_christ christ muslim hindu buddhist jew  atheist confus ///
 yrm1 yrm2 yrm3 yrm4 yrm5 yrm6 yrm7  yrm9 [aw=WGT], ab(WP5) cl(WP5)
outreg2 using "Regress_Wellbeing_on_Single_Harm_Metric.xls",  excel adjr2 dec(3) label ///
addnote("All models include country fixed effects. Errors are clustered at country level.")  
}

**TSTAT PLOTS-
foreach x in harm_index  unemployed affected_alot  ///
 temp_layoff lost_hours lost_income lost_job  { 
gen T`x'=.
gen beta`x'=.
gen se`x'=.
gen T2`x'=.
gen beta2`x'=.
gen se2`x'=.
gen T3`x'=.
gen beta3`x'=.
gen se3`x'=.
gen T4`x'=.
gen beta4`x'=.
gen se4`x'=.
gen T5`x'=.
gen beta5`x'=.
gen se5`x'=.
gen T6`x'=.
gen beta6`x'=.
gen se6`x'=.
gen T7`x'=.
gen beta7`x'=.
gen se7`x'=.
gen T8`x'=.
gen beta8`x'=.
gen se8`x'=.
}

*Living worse 
foreach x in harm_index  unemployed affected_alot  ///
 temp_layoff lost_hours lost_income lost_job  { 
areg living_worse `x' ///
 city suburb town foreign out_labor elementary secondary ageg1 ageg2 ageg3 ageg4 ageg5 ageg6  male incQ1 incQ2 incQ3 incQ4  ///
 married have_children cath protest_christ christ muslim hindu buddhist jew  atheist confus ///
 yrm1 yrm2 yrm3 yrm4 yrm5 yrm6 yrm7  yrm9 [aw=WGT], ab(WP5) cl(WP5)
outreg2 using "Regress_Wellbeing_on_Single_Harm_Metric.xls",  excel adjr2 dec(3) label ///
addnote("All models include country fixed effects. Errors are clustered at country level.")  
replace beta`x'=_b[`x'] 
replace se`x'=_se[`x'] 
replace T`x'=beta`x'/se`x'
}


*Low life evaluation
gen low_life=1 if life_eval<7
replace low_life=0 if life_eval>=7 & life_eval!=.
sum low_life

foreach x in harm_index  unemployed affected_alot  ///
 temp_layoff lost_hours lost_income lost_job  { 
areg low_life `x' ///
 city suburb town foreign out_labor elementary secondary ageg1 ageg2 ageg3 ageg4 ageg5 ageg6  male incQ1 incQ2 incQ3 incQ4  ///
 married have_children cath protest_christ christ muslim hindu buddhist jew  atheist confus ///
 yrm1 yrm2 yrm3 yrm4 yrm5 yrm6 yrm7  yrm9 [aw=WGT], ab(WP5) cl(WP5)
replace beta2`x'=_b[`x'] 
replace se2`x'=_se[`x'] 
replace T2`x'=beta2`x'/se2`x'
}

*Worry
foreach x in harm_index  unemployed affected_alot  ///
 temp_layoff lost_hours lost_income lost_job  { 
areg Yworry `x' ///
 city suburb town foreign out_labor elementary secondary ageg1 ageg2 ageg3 ageg4 ageg5 ageg6  male incQ1 incQ2 incQ3 incQ4  ///
 married have_children cath protest_christ christ muslim hindu buddhist jew  atheist confus ///
 yrm1 yrm2 yrm3 yrm4 yrm5 yrm6 yrm7  yrm9 [aw=WGT], ab(WP5) cl(WP5)
replace beta3`x'=_b[`x'] 
replace se3`x'=_se[`x'] 
replace T3`x'=beta3`x'/se3`x'
}

*Can't afford food
foreach x in harm_index  unemployed affected_alot  ///
 temp_layoff lost_hours lost_income lost_job  { 
areg not_enough_food `x' ///
 city suburb town foreign out_labor elementary secondary ageg1 ageg2 ageg3 ageg4 ageg5 ageg6  male incQ1 incQ2 incQ3 incQ4  ///
 married have_children cath protest_christ christ muslim hindu buddhist jew  atheist confus ///
 yrm1 yrm2 yrm3 yrm4 yrm5 yrm6 yrm7  yrm9 [aw=WGT], ab(WP5) cl(WP5)
replace beta4`x'=_b[`x'] 
replace se4`x'=_se[`x'] 
replace T4`x'=beta4`x'/se4`x'
}


**Horse race t-stat--living worse
areg living_worse  unemployed affected_alot  ///
temp_layoff lost_hours lost_income lost_job  ///
city suburb town foreign out_labor elementary secondary ageg1 ageg2 ageg3 ageg4 ageg5 ageg6  male incQ1 incQ2 incQ3 incQ4  ///
married have_children cath protest_christ christ muslim hindu buddhist jew  atheist confus ///
yrm1 yrm2 yrm3 yrm4 yrm5 yrm6 yrm7  yrm9 [aw=WGT], ab(WP5) cl(WP5)

foreach x in  unemployed affected_alot  ///
temp_layoff lost_hours lost_income lost_job  { 
replace beta5`x'=_b[`x'] 
replace se5`x'=_se[`x'] 
replace T5`x'=beta5`x'/se5`x'
}

**Horse race t-stat--low life
areg low_life  unemployed affected_alot  ///
temp_layoff lost_hours lost_income lost_job  ///
city suburb town foreign out_labor elementary secondary ageg1 ageg2 ageg3 ageg4 ageg5 ageg6  male incQ1 incQ2 incQ3 incQ4  ///
married have_children cath protest_christ christ muslim hindu buddhist jew  atheist confus ///
yrm1 yrm2 yrm3 yrm4 yrm5 yrm6 yrm7  yrm9 [aw=WGT], ab(WP5) cl(WP5)

foreach x in   unemployed affected_alot  ///
temp_layoff lost_hours lost_income lost_job  { 
replace beta6`x'=_b[`x'] 
replace se6`x'=_se[`x'] 
replace T6`x'=beta6`x'/se6`x'
}

**Horse race t-stat--worry
areg Yworry  unemployed affected_alot  ///
temp_layoff lost_hours lost_income lost_job  ///
city suburb town foreign out_labor elementary secondary ageg1 ageg2 ageg3 ageg4 ageg5 ageg6  male incQ1 incQ2 incQ3 incQ4  ///
married have_children cath protest_christ christ muslim hindu buddhist jew  atheist confus ///
yrm1 yrm2 yrm3 yrm4 yrm5 yrm6 yrm7  yrm9 [aw=WGT], ab(WP5) cl(WP5)

foreach x in   unemployed affected_alot  ///
temp_layoff lost_hours lost_income lost_job  { 
replace beta7`x'=_b[`x'] 
replace se7`x'=_se[`x'] 
replace T7`x'=beta7`x'/se7`x'
}

**Horse race t-stat--food
areg not_enough_food  unemployed affected_alot  ///
temp_layoff lost_hours lost_income lost_job  ///
city suburb town foreign out_labor elementary secondary ageg1 ageg2 ageg3 ageg4 ageg5 ageg6  male incQ1 incQ2 incQ3 incQ4  ///
married have_children cath protest_christ christ muslim hindu buddhist jew  atheist confus ///
yrm1 yrm2 yrm3 yrm4 yrm5 yrm6 yrm7  yrm9 [aw=WGT], ab(WP5) cl(WP5)

foreach x in   unemployed affected_alot  ///
temp_layoff lost_hours lost_income lost_job  { 
replace beta8`x'=_b[`x'] 
replace se8`x'=_se[`x'] 
replace T8`x'=beta8`x'/se8`x'
}

**Re-arrange
keep in 1
keep T* se* beta*
drop secondary self_employed_FT
gen ob=1
reshape long T T2 T3 T4 T5 T6 T7 T8 beta beta2 beta3 beta4 beta5 beta6 beta7 beta8 se se2 se3 se4 se5 se6 se7 se8, i(ob) j(variable) string

replace variable="Lost hours" if variable=="lost_hours"
replace variable="Lost income" if variable=="lost_income"
replace variable="Tempoarily laid off" if variable=="temp_layoff"
replace variable="Unemployed (currently)" if variable=="unemployed"
replace variable="Affected a lot" if variable=="affected_alot"
replace variable="Harm index" if variable=="harm_index"
replace variable="Lost job" if variable=="lost_job"

forval x=2/8 {
gen U`x'=beta`x'+(se`x'*1.96)
gen L`x'=beta`x'-(se`x'*1.96)
}
gen U1=beta+(se*1.96)
gen L1=beta-(se*1.96)

**--------------
**Confidence interval plots**
**------------

cd "G:\World_Poll\People\Jonathan_Rothwell\WP\WP COVID\Cojucaro_Kim\WB output\figures\"
erase "Wellbeing1.gph"
erase "Wellbeing2.gph"
erase "Wellbeing3.gph"
erase "Wellbeing4.gph"

graph dot (mean) beta U1 L1 beta5 U5 L5 , over(variable, label(labsize(small)) sort(1)) ///
marker(1, msize(large) msymbol(O) mfcolor(blue%50) mcolor(blue*.7)) ///
marker(2, msize(small) msymbol(Oh) mcolor(blue*.7)) ///
marker(3, msize(small) msymbol(Oh) mcolor(blue*.7)) ///
marker(4, msize(large) msymbol(D) mfcolor(red%50) mcolor(red*.7)) ///
marker(5, msize(small) msymbol(Dh) mcolor(red*.7)) ///
marker(6, msize(small) msymbol(Dh) mcolor(red*.7)) ///
legend(order(1 "Variables run in distinct models" 4 "Variables in same model" )  region(style(none)) size(*.75) rows(1) span)  ///
ytitle("Point estimate with 95% confidence interval") ///
plotregion(color(white)) graphregion(color(white)) yline(0)  ///
saving(Wellbeing1) ///
title("Loss of living standard")

graph dot (mean) beta2 U2 L2 beta6 U6 L6 , over(variable, label(labsize(small)) sort(1)) ///
marker(1, msize(large) msymbol(O) mfcolor(blue%50) mcolor(blue*.7)) ///
marker(2, msize(small) msymbol(Oh) mcolor(blue*.7)) ///
marker(3, msize(small) msymbol(Oh) mcolor(blue*.7)) ///
marker(4, msize(large) msymbol(D) mfcolor(red%50) mcolor(red*.7)) ///
marker(5, msize(small) msymbol(Dh) mcolor(red*.7)) ///
marker(6, msize(small) msymbol(Dh) mcolor(red*.7)) ///
legend(order(1 "Variables run in distinct models" 4 "Variables in same model" )  region(style(none)) size(*.75) rows(1) span)  ///
ytitle("Point estimate with 95% confidence interval") ///
plotregion(color(white)) graphregion(color(white)) yline(0)  ///
saving(Wellbeing2) ///
title("Low life evaluation")

graph dot (mean) beta3 U3 L3 beta7 U7 L7 , over(variable, label(labsize(small)) sort(1)) ///
marker(1, msize(large) msymbol(O) mfcolor(blue%50) mcolor(blue*.7)) ///
marker(2, msize(small) msymbol(Oh) mcolor(blue*.7)) ///
marker(3, msize(small) msymbol(Oh) mcolor(blue*.7)) ///
marker(4, msize(large) msymbol(D) mfcolor(red%50) mcolor(red*.7)) ///
marker(5, msize(small) msymbol(Dh) mcolor(red*.7)) ///
marker(6, msize(small) msymbol(Dh) mcolor(red*.7)) ///
legend(order(1 "Variables run in distinct models" 4 "Variables in same model" )  region(style(none)) size(*.75) rows(1) span)  ///
ytitle("Point estimate with 95% confidence interval") ///
plotregion(color(white)) graphregion(color(white)) yline(0)  ///
saving(Wellbeing3) ///
title("Experienced a lot of worry")

graph dot (mean) beta4 U4 L4 beta8 U8 L8 , over(variable, label(labsize(small)) sort(1)) ///
marker(1, msize(large) msymbol(O) mfcolor(blue%50) mcolor(blue*.7)) ///
marker(2, msize(small) msymbol(Oh) mcolor(blue*.7)) ///
marker(3, msize(small) msymbol(Oh) mcolor(blue*.7)) ///
marker(4, msize(large) msymbol(D) mfcolor(red%50) mcolor(red*.7)) ///
marker(5, msize(small) msymbol(Dh) mcolor(red*.7)) ///
marker(6, msize(small) msymbol(Dh) mcolor(red*.7)) ///
legend(order(1 "Variables run in distinct models" 4 "Variables in same model" )  region(style(none)) size(*.75) rows(1) span)  ///
ytitle("Point estimate with 95% confidence interval") ///
plotregion(color(white)) graphregion(color(white)) yline(0)  ///
saving(Wellbeing4) ///
title("Could not afford food within past year")

grc1leg Wellbeing1.gph Wellbeing2.gph Wellbeing3.gph Wellbeing4.gph   ///
, imargin(2 2 2 2) row(3) col(2) legendfrom(Wellbeing1.gph) iscale(*.75) plotregion(color(white)) graphregion(color(white))  
graph export "Fig1_Wellbeing_plot.png", replace


